const router = require('koa-router')()
const Mock = require('mockjs')
const { list } = Mock.mock({
  "list|100": [{
    "id": "@id",
    "image": "@image(180x120, @color)",
    "title": "@ctitle",
    "desc": "@cword(10, 20)"
  }]
})

router.get('/list', ctx => {
  // 1. 获取搜索数据
  const { q = '' } = ctx.request.query;


  ctx.body = {
    code: 200,
    // 2. 搜索
    data: list.filter(v => {
      return v.title.includes(q) || v.id.includes(q) || v.desc.includes(q)
    }),
    message: 'ok'
  }
})

module.exports = router
